/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts.actions;

import com.myapp.struts.actionform.MaterialFormBean;
import com.myapp.struts.beans.ItemBean;
import com.myapp.struts.dao.MaterialMasterDao;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author pavan
 */
public class InsertItems extends Action {

    private final static String SUCCESS = "success";
    private final static String FAIL = "fail";
    private final MaterialMasterDao idao;
    private boolean status;

    public InsertItems() {
        idao = new MaterialMasterDao();
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        try {
            status = idao.insertItems(form);
            System.out.println("status=" + status);
            if (status == true) {
                return mapping.findForward(SUCCESS);
            } else {
                return mapping.findForward(FAIL);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        return null;
    }
}
